package DAO;

import Damain.emp;
import Utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class EmpAddDaoImpl implements EmpAddDao {
    /**
     * 保存员工
     *
     * @param emp
     */
    @Override
    public void seve(emp emp) {
        Connection connection = null;
        PreparedStatement statement = null;
        connection = JdbcUtils.getConnection();
        String sql = "INSERT INTO t_emp VALUES (null,?,?,?,?,?,?)";
        //emp = new emp();
        try {
            statement = connection.prepareStatement(sql);
            //设置值
            statement.setString(1, emp.getEname());
            statement.setInt(2, emp.getAge());
            statement.setString(3, emp.getSex());
            statement.setInt(4, emp.getSal());
            statement.setString(5, emp.getBirthday());
            statement.setString(6, emp.getEdate());
            //执行
            statement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.close(connection, statement);
        }
    }
}
